import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_14: 播放历史页面, 确认删除全部播放历史')
@allure.issue(
    'https://www.tapd.cn/56767367/sparrow/tcase/view/1156767367001043374?url_cache_key=17e362af8b12add5e45c5e468a11c15a')
class TestCaseMusic14:
    """
    预期结果: 点击确定后，全部播放记录被删除
    """

    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()

        self.music_choice_page = CommonPage(self.driver).get_music_choice_page()
        self.music_index_page = CommonPage(self.driver).get_music_index_page()
        self.music_player_page = CommonPage(self.driver).get_music_player_page()
        self.music_my_collection_page = CommonPage(self.driver).get_music_my_collection_page()
        self.music_play_history_page = CommonPage(self.driver).get_music_play_history_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('music')
        self.driver.quit()

    @allure.story("step1: 进入播放历史页面, 确认播放历史页面有数据")
    @pytest.mark.run(order=141)
    def test_music_14_1_enter_history_page(self):
        try:
            # 进入音乐
            self.launcher_index_page.click_app_list()
            self.launcher_app_list_page.click_appname(TestCase.MUSIC)
            if self.music_choice_page.is_display_title():
                self.music_choice_page.click_skip()

            # 进入播放历史页面
            self.music_index_page.click_my_music()
            self.music_my_collection_page.click_play_history()
            assert self.music_play_history_page.get_history_list_music_title(1)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 删除全部播放历史")
    @pytest.mark.run(order=142)
    def test_music_14_2_clear_history(self):
        try:

            # 确认清除播放历史
            self.music_play_history_page.click_clear_history()
            self.music_my_collection_page.click_confrim_clear()

            # 获取缺省文案
            assert self.music_my_collection_page.get_null_text()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == '__main__':
    pass
